
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define INFOFILE	"/etc/.license"
#define MAXLEN		1024

int main(int argc,char **argv)
{
	char *string = NULL;
	int pf = 0, len = 0;

	if(argc != 2)
	{
		fprintf(stderr,"Usage:%s license\n\a",argv[0]);
		exit(1);
	}
	string = argv[1];
	
	len = strlen(string);

	if ( len > MAXLEN)
	{
		//fprintf(stderr, "Error input info!\n");
		exit(1);
	}

	if ((pf = open(INFOFILE, O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR)) == -1 )
	{	
		//fprintf(stderr, "Error open file!\n");
		exit(1);
	}

	if ( len != write(pf,string ,len))
	{
		//fprintf(stderr,"Error write file!\n");
		exit(1);
	}
	
	printf("Congratulation!\nLicense information have writed to system.\nPlease reboot your system and be available for use.\n");
	
	close(pf);
	return 0;
}

